package com.jp.knowledge.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.PositionKnowlegeMode;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/7/12.
 */

public class JobKnowledgeDragAdapter extends RecycleVAdapter<PositionKnowlegeMode> implements View.OnTouchListener {

	public JobKnowledgeDragAdapter(Context context, @NonNull List<PositionKnowlegeMode> list) {
		super(context, list);
	}

	@Override
	public int getLayoutId(int viewType) {
		return R.layout.activity_sort_head_item;
	}

	@Override
	public void onBind(RecycleVHolder holder, int position) {
		TextView itemBtn = holder.get(R.id.item_name);
		itemBtn.setText(getData(position).getName());
		itemBtn.setTag(holder);
		itemBtn.setOnTouchListener(this);
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		if(itemTouchListener != null)
			return itemTouchListener.onItemTouch(v, event, (RecyclerView.ViewHolder) v.getTag());
		return false;
	}

	private ItemTouchListener itemTouchListener;
	public void setItemTouchListener(ItemTouchListener itemTouchListener){
		this.itemTouchListener = itemTouchListener;
	}
	public interface ItemTouchListener{
		boolean onItemTouch(View v, MotionEvent event, RecyclerView.ViewHolder viewHolder);
	}
}
